//
//  ZMBRechargeResultVC.swift
//  HengYouCai
//
//  Created by wll on 2018/5/29.
//  Copyright © 2018年 lwj. All rights reserved.
//  充值结果页--代码

import UIKit

class ZMBRechargeResultVC: BaseViewController {

    ///支付信息code:  0 成功 1 失败100等待
    public var payResultDic = [String:Any]()
    ///是否来自钱包
    public var isFromAccount: Bool = true
    
    private var phoneNum: String?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.navigationItem.title = "充值"
        self.view.backgroundColor = Normal_EEEColor
        self.createCV()
        
        let code: String = payResultDic["code"] as? String ?? "1"

        var imageNamed: String = ""
        let result = payResultDic["result"] as? [String:String]

        if code == "1" {//失败
            
            imageNamed = "recharge_fail"
            self.bottomBtn.isHidden = false
            self.alertLab.isHidden = false
            self.alertLab.text = result?["message"]
            self.phoneNum = result?["phone"]
            self.bottomBtn.setTitle("  客服电话：" + (self.phoneNum ?? ""), for: .normal)
            
        }else if code == "100" {//等待
            
            imageNamed = "recharge_handle"
            self.bigBtn.isHidden = false
            self.alertLab.isHidden = false
            self.alertLab.text = result?["message"]
            
        }else {//成功
            
            imageNamed = "recharge_success"
            self.leftBtn.isHidden = false
            self.rightBtn.isHidden = false
            self.leftLab.isHidden = false
            self.rightLab.isHidden = false
            self.rightLab.text = (result?["amount"] ?? "0") + "元"
            
        }
        self.resultInfoLab.text = payResultDic["message"] as? String
        self.resultInfoImageV.image = UIImage(named: imageNamed)

    }
    
    ///
    func createCV() {
        
        self.view.addSubview(self.resultInfoImageV)
        self.resultInfoImageV.centerX_sd = self.view.centerX_sd
        self.resultInfoImageV.top_sd = kJcwGetNavHeight() + 50
        
        self.resultInfoLab.frame = CGRect(x: 0, y: self.resultInfoImageV.bottom_sd + 15, width: self.view.width_sd, height: 20)
        self.view.addSubview(self.resultInfoLab)
        
        self.middleWhiteView.frame = CGRect(x: 0, y: self.resultInfoLab.bottom_sd + 50, width: self.view.width_sd, height: 50)
        self.view.addSubview(self.middleWhiteView)
        
        self.leftLab.frame = CGRect(x: 12, y: self.middleWhiteView.top_sd, width: 90, height: 50)
        self.view.addSubview(self.leftLab)
        
        self.rightLab.frame = CGRect(x: 110, y: self.middleWhiteView.top_sd, width: self.view.width_sd - 122, height: 50)
        self.view.addSubview(self.rightLab)

        self.alertLab.frame = self.middleWhiteView.frame
        self.view.addSubview(self.alertLab)
        
        let spaceX: CGFloat = 15
        let btnW: CGFloat = (self.view.width_sd - spaceX*3)/2.0
    
        self.leftBtn.frame = CGRect(x: spaceX, y: self.middleWhiteView.bottom_sd + 30, width: btnW, height: 45)
        self.view.addSubview(self.leftBtn)
        
        self.rightBtn.frame = CGRect(x: self.leftBtn.right_sd+spaceX, y: self.leftBtn.top_sd, width: btnW, height: 45)
        self.view.addSubview(self.rightBtn)
        
        self.bigBtn.frame = CGRect(x: spaceX, y: self.leftBtn.top_sd, width: self.view.width_sd-spaceX*2, height: 45)
        self.view.addSubview(self.bigBtn)
        
        self.view.addSubview(self.bottomBtn)
        self.bottomBtn.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.bottom.equalToSuperview().offset(-88.ah_wl)
        }
    }
    
    
    //MARK:点击事件
    ///回到账户
    @objc func toAccount() {
        self.tabBarController?.selectedIndex = 2
        self.navigationController?.popToRootViewController(animated: true)
    }
    ///立即投资
    @objc func toPurchase() {
        //立即投资 两种情况 1.充值界面 过来跳列表 2. 投资界面过来 原路返回
        if (self.isFromAccount) {//1
            self.tabBarController?.selectedIndex = 1;
            self.navigationController?.popToRootViewController(animated: true)
        }else{//2
            self.popToViewController(at: 2)
        }
    }
    ///拨打客服电话
    @objc func callTel() {
        JCWCallTel(self.phoneNum ?? "")
    }
    
    ///充值结果图片信息
    let resultInfoImageV: UIImageView = {
        let temp = UIImageView()
        temp.bounds = CGRect(x: 0, y: 0, width: 130, height: 97.5)
        return temp
    }()
    ///充值文字信息
    let resultInfoLab: UILabel = {
        let temp = UILabel()
        temp.font = Font_WL(19)
        temp.textColor = Normal_666Color
        temp.textAlignment = .center
        return temp
    }()
    ///中间小白条视图
    let middleWhiteView: UIView = {
        let temp = UIView()
        temp.backgroundColor = UIColor.white
        return temp
    }()
    ///充值金额左标签
    let leftLab: UILabel = {
        let temp = UILabel()
        temp.font = Font_WL(14)
        temp.text = "充值金额"
        temp.textColor = Normal_333Color
        temp.isHidden = true
        temp.textAlignment = .left
        return temp
    }()
    ///充值金额右标签
    let rightLab: UILabel = {
        let temp = UILabel()
        temp.font = Font_WL(13)
        temp.textColor = Normal_RedColor
        temp.isHidden = true
        temp.textAlignment = .right
        return temp
    }()
    ///充值错误提示
    let alertLab: UILabel = {
        let temp = UILabel()
        temp.font = Font_WL(14)
        temp.textColor = Normal_999Color
        temp.isHidden = true
        temp.textAlignment = .center
        return temp
    }()

    ///大按钮
    let bigBtn: UIButton = {
        let temp = UIButton(type: .custom)
        temp.setTitle("回到账户", for: .normal)
        temp.titleLabel?.font = Font_WL(15)
        temp.backgroundColor = Normal_RedColor
        temp.isHidden = true
        temp.layer.cornerRadius = 5
        temp.addTarget(self, action: #selector(toAccount), for: .touchUpInside)
        return temp
    }()
    ///左按钮
    let leftBtn: UIButton = {
        let temp = UIButton(type: .custom)
        temp.setTitle("回到账户", for: .normal)
        temp.setTitleColor(Normal_RedColor, for: .normal)
        temp.titleLabel?.font = Font_WL(15)
        temp.layer.borderWidth = 0.5
        temp.layer.cornerRadius = 5
        temp.layer.borderColor = Normal_RedColor.cgColor
        temp.isHidden = true
        temp.addTarget(self, action: #selector(toAccount), for: .touchUpInside)
        return temp
    }()
    ///右按钮
    let rightBtn: UIButton = {
        let temp = UIButton(type: .custom)
        temp.setTitle("立即投资", for: .normal)
        temp.titleLabel?.font = Font_WL(15)
        temp.backgroundColor = Normal_RedColor
        temp.isHidden = true
        temp.layer.cornerRadius = 5
        temp.addTarget(self, action: #selector(toPurchase), for: .touchUpInside)
        return temp
    }()
    ///客服电话按钮
    let bottomBtn: UIButton = {
        let temp = UIButton(type: .custom)
        temp.setTitle("客服电话：", for: .normal)
        temp.setTitleColor(Normal_666Color, for: .normal)
        temp.titleLabel?.font = Font_WL(15)
        temp.isHidden = true
        temp.setImage(UIImage(named: "recharge_telephone"), for: .normal)
        temp.addTarget(self, action: #selector(callTel), for: .touchUpInside)
        return temp
    }()
}
